package com.g.ocache.impl.index;

import java.util.concurrent.atomic.AtomicBoolean;

import com.g.ocache.index.IndexLoader;


/**
 * 
 * @author zhangyf
 * @param <K>
 * @param <V>
 */
public abstract class AbstractIndexLoader<K, V> implements IndexLoader<K, V> {
	//
	private final AtomicBoolean started = new AtomicBoolean(false);
	
	/**
	 * 
	 */
	public boolean isRunning() {
		return started.get();
	}
	
	public void start() {
		// Precondition checking
		if(!started.compareAndSet(false, true)) {
			throw new IllegalStateException("the index loader has already been started");
		}
		
		// NOP
	}
	
	public void stop() {
		// Precondition checking
		if(!started.compareAndSet(true, false)) {
			return;
		}
		
		// NOP
	}
}
